﻿using System;
using System.Html.DOM;
using System.Html.DOM.CSS;

namespace RexToy.UI.Controls
{
    public class Spin : Control
    {
        private string __text;
        public string Text
        {
            get { return __text; }
            set
            {
                this.__text = value;
                var dom = this.__domNode.SearchByName("h1");
                dom._element.InnerHTML = value;
            }
        }

        public Spin(string text)
        {
            this.__text = text;
            this.__domNode = RexToy.UI.Controls.DomNode.Create(new DomNodeCreateOptions()
            {
                tag = Tag.Div,
                className = "ui-loader ui-body-a ui-corner-all",
                items = new DomNodeCreateOptions[]{ 
                    new DomNodeCreateOptions(){
                        tag= Tag.Span,
                        className= "ui-icon ui-icon-loading spin"
                    },
                    new DomNodeCreateOptions(){
                        tag= Tag.H1,
                        hashName= "h1",
                        innerHTML= text
                    }
                }
            });
        }

        public override void Display(bool show)
        {
            var style = this.__domNode.GetStyle();
            style.Display = show ? System.Html.DOM.CSS.Display.Block : System.Html.DOM.CSS.Display.None;

            var t = (RexToy.UI.Global.Window.GetSize().Height - this.GetSize().Height) / 2;
            style.MarginTop = t + "px";
        }
    }
}
